# Maintainer: Bartłomiej Piotrowski <bpiotrowski@archlinux.org>
# Maintainer: Morten Linderud <foxboron@archlinux.org>

pkgname=toolbox
pkgver=0.0.99.4
pkgrel=2
pkgdesc='Unprivileged development environment'
arch=(loong64 x86_64)
url='https://github.com/containers/toolbox'
license=(APACHE)
depends=(podman bash flatpak)
makedepends=(go shellcheck go-md2man bash-completion ninja git meson podman)
_commit=f7c4c7dedb34be33333065296275869e77464400	#refs/tags/0.0.99.4^{}
source=("git+$url#commit=$_commit")
sha256sums=('SKIP')

pkgver() {
  cd toolbox
  git describe --tags | sed 's/\([^-]*-g\)/r\1/;s/-/./g'
}

prepare() {
  cd toolbox
  # Fixes https://github.com/containers/toolbox/issues/1246
  git cherry-pick -n 816a7cab9e2f02f2eb828062be54ffef2e3666dc
  git cherry-pick -n f555029304415a06bde410deb879cd2cc7dad444
  git cherry-pick -n fc5f568c5d82f4a16982268fa67092e52be91fbe
    
  # Fixes FS#79769
  git cherry-pick -n 1cc9e07b7c36fe9f9784b40b58f0a2a3694dd328
  git cherry-pick -n 219f5b4be428388f2b8cc12a7480c4a6922b59ca
}

build() {
  export GOFLAGS="-buildmode=pie -trimpath -mod=readonly -modcacherw"
  export CGO_LDFLAGS="${LDFLAGS}"
  export CGO_CFLAGS="${CFLAGS}"
  export CGO_CPPFLAGS="${CPPFLAGS}"
  export CGO_CXXFLAGS="${CXXFLAGS}"
  arch-meson toolbox build -D profile_dir=/etc/profile.d
  ninja -C build
}

package() {
  DESTDIR="$pkgdir" ninja -C build install
}
